package com.ljy.my_study.动态规划.矩阵取值;

import java.util.Scanner;

/** 
* @author James
* @date 2018年6月15日 
*/
public class TestMain {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] dp = new int[n + 1];
        int[] readArr = new int[n + 1];
        for (int i = 0; i < n; i++) {
        	String line=in.next();
        	String[] strArr=line.split(",");
            for (int k = 1; k < n + 1; k++) {
            	if(strArr.length-1<k) {
            		readArr[k]=0;
            	}else {
            		readArr[k]=Integer.valueOf(strArr[k]);
            	}
//            	readArr[k] = in.nextInt();
            }
            for (int j = 1; j < n + 1; j++)
                dp[j] = Math.max(dp[j], dp[j - 1]) + readArr[j];
        }
        System.out.println(dp[n]);
	}
	
	public void test() {
		Scanner in = new Scanner(System.in);
		in.nextLine();
	}
}
